﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;

using Wuqi.Webdiyer;

using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Web;
using Maticsoft.DBUtility;

namespace SkWeb.FASJ
{
    public partial class WellSchemeManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                BDMenuBLL menuBLL = new BDMenuBLL();
                lblPath.Text = menuBLL.GetTitlePath(Request["mnu_id"]);
            }
            catch (Exception ex)
            {

            }

            if (!IsPostBack)
            {
                if (Globals.CurrentUserInfo.JSE_ID != 1)
                {
                    txtSJR.Text = Globals.CurrentUserInfo.USE_NAME;
                    txtSJR.Enabled = false;
                }
                txtDateStart.Text = DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
                txtDateEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
                SearchData(txtJH.Text.Trim(), txtSJR.Text.Trim(), txtDateStart.Text, txtDateEnd.Text);
            }
        }

        protected void aspNetPagerSearch_PageChanging(object sender, PageChangingEventArgs e)
        {
            aspNetPagerSearch.CurrentPageIndex = e.NewPageIndex;
            SearchData(Request.Form["txtJH"].Trim(), Request.Form["txtSJR"].Trim(),
                    Request.Form["txtDateStart"],
                    Request.Form["txtDateEnd"]);
        }

        private void SearchData(string jh, string shr, string dateStart, string dateEnd)
        {
            try
            {
                int pageIndex = this.aspNetPagerSearch.CurrentPageIndex;
                int pageSize = this.aspNetPagerSearch.PageSize;
                int recordCount = 0;


                DataTable table = null;
                SkgysjbBLL skgyBLL = new SkgysjbBLL();

                table = skgyBLL.QueryWellSchemeDesignByUser(jh, shr, 
                    DateTime.Parse(dateStart).ToString("yyyy-MM-dd"), DateTime.Parse(dateEnd).ToString("yyyy-MM-dd"),
                    pageSize, pageIndex, out recordCount);

                this.gv_wellSchemeDesignList.PageSize = pageSize;

                this.gv_wellSchemeDesignList.DataSource = table;
                this.gv_wellSchemeDesignList.DataBind();
                this.aspNetPagerSearch.RecordCount = recordCount;
                this.aspNetPagerSearch.DataBind();
            }
            catch (Exception ex)
            {

            }


        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            SearchData(Request.Form["txtJH"].Trim(), Request.Form["txtSJR"].Trim(),
                    Request.Form["txtDateStart"],
                    Request.Form["txtDateEnd"]);
        }

    
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            GridViewRow row = btn.NamingContainer as GridViewRow;
            string strJh=row.Cells[0].Text.Trim();
            string strTmp=row.Cells[6].Text.Trim();
            string strSql = "select id from skgysjb where trim(jh)='" + strJh + "'";
            string strJing_id = OracleHelper.Query(strSql).Tables[0].Rows[0][0].ToString();
            
            strSql = "select tmp_id from tb_template_menu where tmp_mc='" + strTmp + "'";
            string strTemplate_id = OracleHelper.Query(strSql).Tables[0].Rows[0][0].ToString();
            strSql = "delete from tb_fa where jing_id=" + strJing_id + "and tmp_id=" + strTemplate_id;
            OracleHelper.ExecuteSql(strSql);

            txtDateStart.Text = DateTime.Now.AddMonths(-2).ToString("yyyy-MM-dd");
            txtDateEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
            SearchData(txtJH.Text.Trim(), txtSJR.Text.Trim(), txtDateStart.Text, txtDateEnd.Text);

        }
    }
}